//对axios进行二次封装
import axios from "axios";
import nprogress from "nprogress";
import "nprogress/nprogress.css";
//创建一个axios实例
const requests = axios.create({
  baseURL: "/mock",
  timeout: 5000,
});
//请求拦截器
requests.interceptors.request.use((config) => {
  //config是一个配置对象，对象含header请求头
  nprogress.start();
  return config;
});
//响应拦截器
requests.interceptors.response.use(
  (res) => {
    //成功的回调
    nprogress.done();
    return res.data;
  },
  (error) => {
    //终结promise链
    return Promise.reject(new Error("failed"));
  }
);

export default requests;
